package com.woniuxy.service.Impl;

import com.woniuxy.config.MqConfig;
import com.woniuxy.entity.Food;

import com.woniuxy.entity.foodinfo;
import com.woniuxy.mapper.FoodMapper;
import com.woniuxy.service.FoodService;
import com.woniuxy.utils.IDUtils;
import com.woniuxy.vo.UserFoodOrderDetailVo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FoodServiceImpl implements FoodService {
    @Autowired
    private FoodMapper foodMapper;

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public List<Food> findAll() {
        return foodMapper.findAll();
    }

    @Override
    public void addfoodOrder(foodinfo fi) {
       fi.setUserinfoId(IDUtils.randomId());
       fi.setStatus("待支付");
       rabbitTemplate.convertAndSend(MqConfig.ORDER_EXCHANGE, MqConfig.ORDER_ROUTING_KEY, fi);



        foodMapper.addfoodOrder(fi);
    }

    @Override
    public List<UserFoodOrderDetailVo> findOrderDetailsByUserId(Integer userId) {
        return foodMapper.findOrderDetailsByUserId(userId);
    }

    @Override
    public void updateByUserinfoId(String outTradeNo) {

        foodMapper.updateByUserinfoId(outTradeNo);
    }

    @Override
    public void updateByUserinfoId2(String outTradeNo) {
        foodMapper.updateByUserinfoId2(outTradeNo);
    }

    @Override
    public foodinfo findfoodinfoByUserinfoId(String id) {
        return foodMapper.findfoodinfoByUserinfoId(id);
    }

}
